﻿using System;
#if DEBUG
using System.Diagnostics;
#endif // #if DEBUG
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using FRL.DebtChased.WorkflowObjects;

namespace FRL.DebtChased.WorkflowEditor
{

	/// <summary>
	/// Declaration of ActionBoingCtrl class
	/// Control to represent actions as a rounded rectangle, with/without a leg
	/// </summary>
	public class ActionBoingCtrl : UserControl
	{

		/////////////////////////////////////////////////////////////
		// Nested classes

		private struct ColorSet
		{
			internal Color m_colUpperBand;
			internal Color m_colBand;
			internal Color m_colLowerBand;
			internal Color m_colStroke;
		}

		/////////////////////////////////////////////////////////////
		// Enumerations

		private enum ePathType
		{
			TopRoundedRectangle,
			BottomLeg,
			Outline,
		}

		/////////////////////////////////////////////////////////////
		// Construction

		private const int Rounding = 12;

		private const int MainBodyHeight = 36;
		private const int MainBodyWidth = 560;

		public const int DragCenterX = MainBodyWidth / 2;
		public const int DragCenterY = MainBodyHeight / 2;

		public const int LegThickness = 24;

		private const int StrokeThickness = 2;
		private const int SelectedStrokeThickness = 2;

		/////////////////////////////////////////////////////////////
		#region Action Color Sets

		private static ColorSet m_CallDebtorColorSet = new ColorSet()
		{
			m_colUpperBand = Color.FromArgb(0xFF, 0xa8, 0xd0, 0x53),
			m_colBand = Color.FromArgb(0xFF, 0xa7, 0xcf, 0x51),
			m_colLowerBand = Color.FromArgb(0xFF, 0xb5, 0xd5, 0x6b),
			m_colStroke = Color.FromArgb(0xFF, 0x55, 0xbb, 0x55)
		};

		private static ColorSet m_SendLetterFaxColorSet = new ColorSet()
		{
			m_colUpperBand = Color.FromArgb(0xFF, 0x53, 0xa8, 0xd0),
			m_colBand = Color.FromArgb(0xFF, 0x51, 0xa7, 0xcf),
			m_colLowerBand = Color.FromArgb(0xFF, 0x6b, 0xb5, 0xd5),
			m_colStroke = Color.FromArgb(0xFF, 0x55, 0x55, 0xbb)
		};

		private static ColorSet m_SendEmailColorSet = new ColorSet()
		{
			m_colUpperBand = Color.FromArgb(0xFF, 0xd0, 0x53, 0xa8),
			m_colBand = Color.FromArgb(0xFF, 0xcf, 0x51, 0xa7),
			m_colLowerBand = Color.FromArgb(0xFF, 0xd5, 0x6b, 0xb5),
			m_colStroke = Color.FromArgb(0xFF, 0xbb, 0x55, 0x55)
		};

		private static ColorSet m_SendSMSColorSet = new ColorSet()
		{
			m_colUpperBand = Color.FromArgb(0xFF, 0xd0, 0xa8, 0x53),
			m_colBand = Color.FromArgb(0xFF, 0xcf, 0xa7, 0x51),
			m_colLowerBand = Color.FromArgb(0xFF, 0xd5, 0xb5, 0x6b),
			m_colStroke = Color.FromArgb(0xFF, 0xbb, 0x55, 0x55)
		};

		private static ColorSet m_PopupColorSet = new ColorSet()
		{
			m_colUpperBand = Color.FromArgb(0xFF, 0xff, 0x55, 0x55),
			m_colBand = Color.FromArgb(0xFF, 0x77, 0x22, 0x22),
			m_colLowerBand = Color.FromArgb(0xFF, 0xd5, 0x55, 0x55),
			m_colStroke = Color.FromArgb(0xFF, 0xbb, 0x55, 0x55)
		};

		private static ColorSet m_SearchColorSet = new ColorSet()
		{
			m_colUpperBand = Color.FromArgb(0xFF, 0xff, 0x55, 0xf5),
			m_colBand = Color.FromArgb(0xFF, 0x77, 0x22, 0x82),
			m_colLowerBand = Color.FromArgb(0xFF, 0xd5, 0x55, 0xf5),
			m_colStroke = Color.FromArgb(0xFF, 0xbb, 0x55, 0xf5)
		};

		private static ColorSet m_NotifyManagerColorSet = new ColorSet()
		{
			m_colUpperBand = Color.FromArgb(0xFF, 255, 128, 0),
			m_colBand = Color.FromArgb(0xFF, 206, 196, 0),
			m_colLowerBand = Color.FromArgb(0xFF, 255, 158, 62),
			m_colStroke = Color.FromArgb(0xFF, 206, 196, 0)
		};

		private static ColorSet m_ManualColorSet = new ColorSet()
		{
			m_colUpperBand = Color.FromArgb(0xFF, 128, 128, 192),
			m_colBand = Color.FromArgb(0xFF, 100, 100, 179),
			m_colLowerBand = Color.FromArgb(0xFF, 128, 128, 192),
			m_colStroke = Color.FromArgb(0xFF, 100, 100, 179)
		};

		#endregion Action Color Sets

		/////////////////////////////////////////////////////////////
		// Attributes

		private bool m_bShowLeg = true;
		public bool ShowLeg
		{
			get { return m_bShowLeg; }
			set { m_bShowLeg = value; }
		}

		private bool m_bSelected = false;
		public bool IsSelected
		{
			get { return m_bSelected; }
			set 
			{ 
				m_bSelected = value;
				if (m_bSelected)
				{
					m_pathWhole.StrokeDashArray = m_dblStrokeDashArray;
					m_pathWhole.Stroke = m_solidSelectedBrush;
					m_pathWhole.StrokeThickness = SelectedStrokeThickness;
				}
				else
				{
					m_pathWhole.StrokeDashArray = null;
					m_pathWhole.Stroke = m_solidStrokeBrush;
					m_pathWhole.StrokeThickness = StrokeThickness;
				}
			}
		}

		private WorkflowAction_Base m_underlyingAction;
		public WorkflowAction_Base UnderlyingAction
		{
			get { return m_underlyingAction; }
		}

		private int m_iLegRows = -1;

		private TextBlock m_tbAction;
		private TextBlock m_tbLineA;
		private TextBlock m_tbLineB;

		private Canvas m_LayoutRoot;
		private Path m_pathWhole;
		private Path m_pathTop;
		private Path m_pathBottom;
		private Rectangle[] m_rectPriority;
		private Path m_pathPriorityPlus;

		private LinearGradientBrush m_linearFillBrush;
		private SolidColorBrush m_solidStrokeBrush;
		private SolidColorBrush m_solidSelectedBrush;

		private DoubleCollection m_dblStrokeDashArray;

		/////////////////////////////////////////////////////////////
		// Construction

		public ActionBoingCtrl()
		{

			// Initialize member variables
			m_dblStrokeDashArray = new DoubleCollection();
			m_dblStrokeDashArray.Add(1);
			m_dblStrokeDashArray.Add(1);

			// Setup layout canvas
			m_LayoutRoot = new Canvas();
			m_LayoutRoot.Background = new SolidColorBrush(Colors.Transparent);
			this.Content = m_LayoutRoot;

			// Set layout
			this.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
			this.RenderTransform = new TranslateTransform();

			// Create brushes
			m_linearFillBrush = _createLinearBrush();
			m_solidStrokeBrush = new SolidColorBrush(Colors.Blue);
			m_solidSelectedBrush = new SolidColorBrush(Colors.Black);

			// Build the top path and set brushes
			PathFigure pf = new PathFigure();
			_buildPath(ePathType.TopRoundedRectangle, pf, 0);
			PathGeometry pg = new PathGeometry();
			pg.Figures.Add(pf);
			m_pathTop = new Path();
			m_pathTop.Data = pg;
			m_pathTop.Fill = m_linearFillBrush;
			m_LayoutRoot.Children.Add(m_pathTop);
			Canvas.SetTop(m_pathTop, 2);

			// Create the bottom path object and set brushes
			pg = new PathGeometry();
			pg.Figures.Add(new PathFigure());
			m_pathBottom = new Path();
			m_pathBottom.Data = pg;
			m_pathBottom.Fill = new SolidColorBrush(Colors.Orange);
			m_LayoutRoot.Children.Add(m_pathBottom);
			Canvas.SetTop(m_pathBottom, 2);

			// Create the whole path object and set brushes
			pg = new PathGeometry();
			pg.Figures.Add(new PathFigure());
			m_pathWhole = new Path();
			m_pathWhole.Data = pg; 
			m_pathWhole.Stroke = m_solidStrokeBrush;
			m_pathWhole.StrokeThickness = StrokeThickness;
			m_LayoutRoot.Children.Add(m_pathWhole);
			Canvas.SetTop(m_pathWhole, 2);

			// Create the labels - action
			m_tbAction = new TextBlock();
			m_tbAction.Text = "ACTION";
			m_tbAction.FontSize = 14;
			m_tbAction.FontWeight = FontWeights.Bold;
			m_tbAction.Width = 120;
			m_tbAction.VerticalAlignment = System.Windows.VerticalAlignment.Top;
			m_LayoutRoot.Children.Add(m_tbAction);
			Canvas.SetLeft(m_tbAction, 10);
			Canvas.SetTop(m_tbAction, 9);

			// Create the labels grid
			Grid gridLabels = new Grid();
			gridLabels.Width = 380;
			gridLabels.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(16, GridUnitType.Pixel) });
			gridLabels.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(14, GridUnitType.Pixel) });
			gridLabels.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(380, GridUnitType.Pixel) });
			m_LayoutRoot.Children.Add(gridLabels);
			Canvas.SetLeft(gridLabels, 110);
			Canvas.SetTop(gridLabels, 5);

			// Create the labels - Line A in grid
			m_tbLineA = new TextBlock();
			m_tbLineA.Foreground = new SolidColorBrush(Colors.Black);
			m_tbLineA.Text = "m_lbLineAg";
			m_tbLineA.FontSize = 10;
			m_tbLineA.FontWeight = FontWeights.Bold;
			m_tbLineA.Width = 380;
			m_tbLineA.Height = 16;
			m_tbLineA.TextTrimming = TextTrimming.WordEllipsis;
			m_tbLineA.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
			m_tbLineA.VerticalAlignment = System.Windows.VerticalAlignment.Center;
			gridLabels.Children.Add(m_tbLineA);
			Grid.SetRow(m_tbLineA, 0);

			// Create the labels - Line B
			m_tbLineB = new TextBlock();
			m_tbLineB.Foreground = new SolidColorBrush(Colors.Black);
			m_tbLineB.Text = "m_lbLineBg";
			m_tbLineB.FontSize = 9;
			m_tbLineB.Width = 380;
			m_tbLineB.Height = 14;
			m_tbLineB.TextTrimming = TextTrimming.WordEllipsis;
			m_tbLineB.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
			m_tbLineB.VerticalAlignment = System.Windows.VerticalAlignment.Center;
			gridLabels.Children.Add(m_tbLineB);
			Grid.SetRow(m_tbLineB, 1);

			// Create the priorty labels
			m_rectPriority = new Rectangle[3];
			m_rectPriority[0] = new Rectangle();
			m_rectPriority[0].Fill = new SolidColorBrush(Color.FromArgb(0xFF,0xc7,0x7f,0x83));
			m_rectPriority[0].Width = 10;
			m_rectPriority[0].Height = 14;
			m_rectPriority[1] = new Rectangle();
			m_rectPriority[1].Fill = new SolidColorBrush(Color.FromArgb(0xFF,0xb8,0x4d,0x55));
			m_rectPriority[1].Width = 10;
			m_rectPriority[1].Height = 21;
			m_rectPriority[2] = new Rectangle();
			m_rectPriority[2].Fill = new SolidColorBrush(Color.FromArgb(0xFF,0x9a,0x00,0x00));
			m_rectPriority[2].Width = 10;
			m_rectPriority[2].Height = 26;
			for(int i1=0; i1<3; i1++ )
			{
				m_rectPriority[i1].Stroke = new SolidColorBrush(Colors.White);
				m_rectPriority[i1].StrokeThickness = 1;
				m_LayoutRoot.Children.Add(m_rectPriority[i1]);
				Canvas.SetLeft(m_rectPriority[i1],MainBodyWidth - 48 + (i1 * 13));
				Canvas.SetTop(m_rectPriority[i1],6 + (26 - m_rectPriority[i1].Height));
			}

			// Create the priority plus path
			m_pathPriorityPlus = _createPriorityPlusPath();
			m_LayoutRoot.Children.Add(m_pathPriorityPlus);
			Canvas.SetLeft(m_pathPriorityPlus, MainBodyWidth - 48 + 14 );
			Canvas.SetTop(m_pathPriorityPlus, 7);

		}

		/////////////////////////////////////////////////////////////
		// Operations

		public void SetUnderlyingAction(WorkflowAction_Base action, bool bAnimate)
		{

			// Update the underlying reference
			m_underlyingAction = action;

			// Set the labels
			m_tbAction.Text = m_underlyingAction.GetBoingLabel();
			string[] strSubStrings = action.GetBoingSubStrings();
			m_tbLineA.Text = strSubStrings[0];
			m_tbLineB.Text = strSubStrings[1];

			// Set the priority
			m_pathPriorityPlus.Visibility = ((action.Priority != WorkflowAction_Base.ePriority.Automated) && (action.Priority == WorkflowAction_Base.ePriority.Escalating)) ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed;
			m_rectPriority[0].Visibility = (action.Priority != WorkflowAction_Base.ePriority.Automated) ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed;
			m_rectPriority[1].Visibility = ((action.Priority != WorkflowAction_Base.ePriority.Automated) && (action.Priority == WorkflowAction_Base.ePriority.Medium) || (action.Priority == WorkflowAction_Base.ePriority.High)) ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed;
			m_rectPriority[2].Visibility = ((action.Priority != WorkflowAction_Base.ePriority.Automated) && (action.Priority == WorkflowAction_Base.ePriority.High)) ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed;

			// If the paths have never been drawn...
			if (m_iLegRows == -1)
				SetLegRows(m_underlyingAction.DaySpan, false);

			// Get the brush colours
			ColorSet colorSet;
			if (action is WorkflowAction_PhoneCall)
				colorSet = m_CallDebtorColorSet;
			else if (action is WorkflowAction_NotifyManager)
				colorSet = m_NotifyManagerColorSet;
			else if (action is WorkflowAction_Popup)
				colorSet = m_PopupColorSet;
			else if (action is WorkflowAction_Search)
				colorSet = m_SearchColorSet;
			else if (action is WorkflowAction_SendEmail)
				colorSet = m_SendEmailColorSet;
			else if (action is WorkflowAction_SendSMS)
				colorSet = m_SendSMSColorSet;
			else if (action is WorkflowAction_SendLetterFax)
				colorSet = m_SendLetterFaxColorSet;
			else if (action is WorkflowAction_Manual)
				colorSet = m_ManualColorSet;
			else
			{
#if DEBUG
				Debug.Assert(false);
#endif // #if DEBUG
				colorSet = m_CallDebtorColorSet;
			}
			_setColors( colorSet, bAnimate );

		}

		public void SetLegRows( int iLegRowsIn, bool bForce )
		{

			// Calculate leg rows
			int iLegRows;
			if ((bForce) || (m_bShowLeg))
				iLegRows = iLegRowsIn;
			else
				iLegRows = 0;

			// If the shape needs changing...
			if (iLegRows != m_iLegRows)
			{

				// Update member variable
				m_iLegRows = iLegRows;

				// Rebuild paths
				_buildPath(ePathType.Outline, (m_pathWhole.Data as PathGeometry).Figures[0], m_iLegRows);
				_buildPath(ePathType.BottomLeg, (m_pathBottom.Data as PathGeometry).Figures[0], m_iLegRows);
				m_pathBottom.Visibility = (m_iLegRows > 0) ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed;

			}

		}

		private LinearGradientBrush _createLinearBrush()
		{

			// Declare return variable
			LinearGradientBrush Ftmp = new LinearGradientBrush();
			Ftmp.StartPoint = new Point(0, 0);
			Ftmp.EndPoint = new Point(0, 1);

			// Add the bands of colour - A
			GradientStop stop = new GradientStop();
			stop.Offset = 0;
			stop.Color = Colors.White;
			Ftmp.GradientStops.Add(stop);

			// Add the bands of colour - B
			stop = new GradientStop();
			stop.Offset = 0.46;
			stop.Color = Colors.Red;
			Ftmp.GradientStops.Add(stop);

			// Add the bands of colour - C
			stop = new GradientStop();
			stop.Offset = 0.48;
			stop.Color = Colors.Green;
			Ftmp.GradientStops.Add(stop);

			// Add the bands of colour - D
			stop = new GradientStop();
			stop.Offset = 0.50;
			stop.Color = Colors.Purple;
			Ftmp.GradientStops.Add(stop);

			// Return variable
			return Ftmp;

		}

		private void _buildPath(ePathType pathType, PathFigure pf, int iLegDays)
		{

			// Calculate leg length
			double dblLegLength = (PlannerCanvas.RowHeight * iLegDays);

			// Clear the existing segments
			pf.Segments.Clear();
			pf.IsClosed = true;

			// If outline or top rect, start with rounded rectangle...
			if( (pathType == ePathType.Outline) || (pathType == ePathType.TopRoundedRectangle) )
			{

				// Create a path figure
				pf.StartPoint = new Point(0, Rounding);

				// Top left arc
				pf.Segments.Add(new ArcSegment()
				{
					Point = new Point(Rounding, 0),
					SweepDirection = System.Windows.Media.SweepDirection.Clockwise,
					Size = new Size(Rounding, Rounding)
				});

				// Top horizontal
				pf.Segments.Add(new LineSegment() { Point = new Point(MainBodyWidth - Rounding, 0) });

				// Top right arc
				pf.Segments.Add(new ArcSegment()
				{
					Point = new Point(MainBodyWidth, Rounding),
					SweepDirection = System.Windows.Media.SweepDirection.Clockwise,
					Size = new Size(Rounding, Rounding)
				});

				// Right vertical
				pf.Segments.Add(new LineSegment() { Point = new Point(MainBodyWidth, MainBodyHeight - Rounding) });

				// Bottom right arc
				pf.Segments.Add(new ArcSegment()
				{
					Point = new Point(MainBodyWidth - Rounding, MainBodyHeight),
					SweepDirection = System.Windows.Media.SweepDirection.Clockwise,
					Size = new Size(Rounding, Rounding)
				});

			}

			// If this is the upper rect, or 1 day outline...
			if(
				(pathType == ePathType.TopRoundedRectangle)
				||
				( (pathType == ePathType.Outline) && (iLegDays==0))
			)
			{

				// Bottom hortizontal
				pf.Segments.Add(new LineSegment() { Point = new Point(Rounding, MainBodyHeight) });

				// Bottom left arc
				pf.Segments.Add(new ArcSegment()
				{
					Point = new Point(0, MainBodyHeight - Rounding),
					SweepDirection = System.Windows.Media.SweepDirection.Clockwise,
					Size = new Size(Rounding, Rounding)
				});

				// Left vertical
				pf.Segments.Add(new LineSegment() { Point = new Point(0, Rounding) });

			}

			// If this is the main outline and legged...
			if ( (pathType == ePathType.Outline) && (iLegDays>0) )
			{

				// bottom horizontal
				pf.Segments.Add(new LineSegment() { Point = new Point(LegThickness + Rounding, MainBodyHeight) });

			}

			// If this is the bottom path...
			if (pathType == ePathType.BottomLeg)
			{

				// Start at right side drop
				pf.StartPoint = new Point(0, MainBodyHeight - Rounding);

				// top slant to right
				pf.Segments.Add(new LineSegment() { Point = new Point(LegThickness + Rounding, MainBodyHeight) });

			}

			// If this is the main outline or bottom...
			if ( 
				((pathType == ePathType.Outline)&&(iLegDays>0)) 
				|| 
				(pathType == ePathType.BottomLeg) 
			)
			{

				// Inverted arc
				pf.Segments.Add(new ArcSegment()
				{
					Point = new Point(LegThickness, MainBodyHeight + Rounding),
					SweepDirection = System.Windows.Media.SweepDirection.Counterclockwise,
					Size = new Size(Rounding, Rounding)
				});

				// right side drop
				pf.Segments.Add(new LineSegment() { Point = new Point(LegThickness, MainBodyHeight + dblLegLength - Rounding) });

				// Bottom leg right arc
				pf.Segments.Add(new ArcSegment()
				{
					Point = new Point(LegThickness - Rounding, MainBodyHeight + dblLegLength),
					SweepDirection = System.Windows.Media.SweepDirection.Clockwise,
					Size = new Size(Rounding, Rounding)
				});

				// leg base horizontal
				pf.Segments.Add(new LineSegment() { Point = new Point(Rounding, MainBodyHeight + dblLegLength) });

				// Bottom leg left arc
				pf.Segments.Add(new ArcSegment()
				{
					Point = new Point(0, MainBodyHeight + dblLegLength - Rounding),
					SweepDirection = System.Windows.Media.SweepDirection.Clockwise,
					Size = new Size(Rounding, Rounding)
				});

			}

			// If this is the bottom path...
			if (pathType == ePathType.BottomLeg)
			{

				// right side return
				pf.Segments.Add(new LineSegment() { Point = new Point(0, MainBodyHeight) });

			}

			// If this is the main outline...
			if ( (pathType == ePathType.Outline) && (iLegDays>0) )
			{

				// right side return
				pf.Segments.Add(new LineSegment() { Point = new Point(0, Rounding) });

			}

		}

		private Path _createPriorityPlusPath()
		{

			// Declare return variable
			Path Ftmp = new Path();

			// Set brushes
			Ftmp.Fill = new SolidColorBrush(Color.FromArgb(0xFF,0x9a,0,0));
			Ftmp.Stroke = new SolidColorBrush(Colors.White); 
			Ftmp.StrokeThickness = 1;

			// Create path figure
			PathFigure pf = new PathFigure();
			pf.StartPoint = new Point(9,0);
			pf.Segments.Add( new LineSegment() { Point = new Point(15,0) } );
			pf.Segments.Add( new LineSegment() { Point = new Point(15,9) } );
			pf.Segments.Add( new LineSegment() { Point = new Point(24,9) } );
			pf.Segments.Add( new LineSegment() { Point = new Point(24,15) } );
			pf.Segments.Add( new LineSegment() { Point = new Point(15,15) } );
			pf.Segments.Add( new LineSegment() { Point = new Point(15,24) } );
			pf.Segments.Add( new LineSegment() { Point = new Point(9,24) } );
			pf.Segments.Add( new LineSegment() { Point = new Point(9,15) } );
			pf.Segments.Add( new LineSegment() { Point = new Point(0,15) } );
			pf.Segments.Add( new LineSegment() { Point = new Point(0,9) } );
			pf.Segments.Add( new LineSegment() { Point = new Point(9,9) } );
			pf.IsClosed = true;

			// Create geometry
			PathGeometry pg = new PathGeometry();
			pg.Figures.Add(pf);
			Ftmp.Data = pg;

			// Return variable
			return Ftmp;

		}

		private void _setColors( ColorSet colorSet, bool bAnimate )
		{

			// If animating...
			if (bAnimate)
			{

				// Setup the story board
				Storyboard storyboard = new Storyboard();

				// Create animation for stroke
				ColorAnimation animStrokeBrush = new ColorAnimation();
				animStrokeBrush.To = colorSet.m_colStroke;
				animStrokeBrush.Duration = TimeSpan.FromTicks(60 * 100 * 1000);
				Storyboard.SetTarget(animStrokeBrush, m_pathWhole);
				Storyboard.SetTargetProperty(animStrokeBrush, new PropertyPath("(Path.Stroke).(SolidColorBrush.Color)"));

				// Create animation for fill A
				ColorAnimation animFillA = new ColorAnimation();
				animFillA.To = colorSet.m_colUpperBand;
				animFillA.Duration = animStrokeBrush.Duration;
				Storyboard.SetTarget(animFillA, m_pathTop);
				Storyboard.SetTargetProperty(
					animFillA,
					new PropertyPath("(Path.Fill).(LinearGradientBrush.GradientStops)[1].(GradientStop.Color)")
				);

				// Create animation for fill B
				ColorAnimation animFillB = new ColorAnimation();
				animFillB.To = colorSet.m_colBand;
				animFillB.Duration = animStrokeBrush.Duration;
				Storyboard.SetTarget(animFillB, m_pathTop);
				Storyboard.SetTargetProperty(
					animFillB,
					new PropertyPath("(Path.Fill).(LinearGradientBrush.GradientStops)[2].(GradientStop.Color)")
				);

				// Create animation for fill C
				ColorAnimation animFillC = new ColorAnimation();
				animFillC.To = colorSet.m_colLowerBand;
				animFillC.Duration = animStrokeBrush.Duration;
				Storyboard.SetTarget(animFillC, m_pathTop);
				Storyboard.SetTargetProperty(
					animFillC,
					new PropertyPath("(Path.Fill).(LinearGradientBrush.GradientStops)[3].(GradientStop.Color)")
				);

				// Begin the storyboard
				storyboard.Children.Add(animStrokeBrush);
				storyboard.Children.Add(animFillA);
				storyboard.Children.Add(animFillB);
				storyboard.Children.Add(animFillC);
				storyboard.Begin();
				 
			}
			else
			{

				// Set colours
				m_solidStrokeBrush.Color = colorSet.m_colStroke;
				m_linearFillBrush.GradientStops[1].Color = colorSet.m_colUpperBand;
				m_linearFillBrush.GradientStops[2].Color = colorSet.m_colBand;
				m_linearFillBrush.GradientStops[3].Color = colorSet.m_colLowerBand;

			}

			// The bottom path is never animated
			(m_pathBottom.Fill as SolidColorBrush).Color = colorSet.m_colLowerBand;

		}

	}

}
